"""
style.py

please edit this file whenever you feel like it.

Basically, what follows is a condensed version of the following pages. 
http://www.python.org/dev/peps/pep-0257/
http://www.python.org/dev/peps/pep-0008/


- no tabs, four space indentation

NAMING
- function names are lowercase with underscores separating words.
- classes start with an uppercase letter and are camelcase

COMMENTS
- single line comments should use "#"
- multiline comments should use docstrings (triple quotes)

DOCSTRINGS (see is_prime)
- each function should have a docstring. if multiline, the ending triple quote
    should go on its own line
- indented four spaces from the ``def fname()`` line.
- use @return, @rtype, @param, @requires whenever possible
- use tags like @note, @bug, when appropriate 


"""

def is_prime(n):
    """ Check if n is prime.
    @raise exception:  n < 2
    @return: True iff n is prime
    @note: This function takes around n/6 time
    """
    if n < 2:
        raise Exception("is_prime() argument error")
    elif n < 4:
        return True
    elif n % 2 == 0:
        return False
    elif n < 9:
        # 5,7 
        return True
    elif n % 3 == 0:
        return False
    else:
        k = 5
        stop = int(math.sqrt(n))
        while k <= stop:
            if n % k == 0:
                return False
            if n % (k + 2) == 0:
                return False
            k += 6
        return True

def primes_generator():
    """ get some primes
    """
    init = [2,3,5,7]
    k = 2
    for i in init:
        yield i
    while True:
        next = 6 * k - 1
        if is_prime(next):
            yield next
        if is_prime(next + 2):
            yield next + 2
        k += 1

foo = primes_generator()
for i in range(100):
    print "the ",str(i) + "th prime is",foo.next()
